// 成绩统计页面
<template>
  <div id="grade_main">
    <span style="display:block;text-align:center;font-size:26px;font-weight:bold;color:red;margin:30px 0;margin-top:60px">学号：{{this.$route.query.studentId}}学生，多次考试成绩走向</span>
    <div id="grade">
      <div ref="box" class="box"></div>
    </div>
    
    <div class="notFound" v-if="isNull">
      <i class="iconfont icon-LC_icon_tips_fill"></i><span>该考生未参加考试</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "grade",
  data() {
    return {
      isNull: false, //原始数据
      tableDataX: [], //x轴数据 保存次数
      tableDataY: [], //y轴数据 保存分数
    }
  },
  mounted() {
    this.score();
  },
  methods: {
    score() {
      let studentId = this.$route.query.studentId
      this.$axios(`/api/score/${studentId}`).then(res => { //根据学生Id查询成绩
        console.log(res)
        if(res.data.code === 200) {
          let rootData = res.data.data
          rootData.forEach((element,index) => {
            this.tableDataX.push(element.subject)
            this.tableDataY.push(element.etScore)
          });
          let boxDom = this.$refs["box"];
          let scoreCharts = this.$echarts.init(boxDom);
          let option = {
            xAxis: {
              type: "category",
              data: this.tableDataX
            },
            tooltip: {
    trigger: 'axis'
  },
  legend: {
    data: ['最高分', '最低分', '当前学生','平均分']
  },
            yAxis: {
              type: "value"
            },
            series: [
              {
                data: this.tableDataY,
                type: "line",
                name: '当前学生',
                itemStyle: { normal: { label: { show: true } } }
              },{
                name: '最高分',
                type: 'line',
           
                data: [87, 79]
              },
              {
                name: '平均分',
                type: 'line',
           
                data: [45, 60]
              },
              {
                name: '最低分',
                type: 'line',
              
                data: [2, 4]
              },
            ]
          };
          scoreCharts.setOption(option);
          scoreCharts.on("mouseover", params => {
            console.log(params.value);
          });
        }else {
          this.isNull = true
        }
      })
    }
  }
};
</script>

<style lang="less" scoped>
#grade {
  display: flex;
  justify-content:center;
  align-item:center;
  .box{
    
    width: 600px;
    height: 400px;
  }
}
</style>
